<?php

namespace app\common\model;



use app\common\model\BaseModel;

use think\Db;

use chrome\ChromePhp;//引入chromephp插件

use common\Common;//公共函数



/**

 * 提供幻灯片管理服务

 * @name LibSlide.php

 * @package cws

 * @category model

 * @link http://www.chanekeji.com

 * @author cx

 * @version 1.0

 * @copyright CHANGE INC

 * @since 2018-12-19

 */

class LibSlide extends BaseModel{

	protected $m_slide;



	/**

	 * 构造函数

	 */

	public function __construct(){

		$this->m_slide = db('base_slide');

		parent::__construct();

	}

	

	/**

	 * 添加数据(返回id,不返回直接使用insert)

	 * @param $condition

	 * @param array $result

	 */

	public function addSlide($condition){

		try {

			$condition['add_time'] = Common::getTime();

			$reslut = $this->m_slide->insertGetId($condition);		

			if(true == $reslut){

				return Common::errorArray(0, "查询成功",$reslut);

			}else{

				return Common::errorArray(1, "查询为空", $reslut);

			}

		}catch (Exception $ex){

			$this->errorLog(__CLASS__, __FUNCTION__, $ex);

			return  Common::errorArray(1, "数据库操作失败", $ex);

		}

	}

	

	

	

	/**

	 * 查询单个幻灯片数据

	 * @param $condition

	 * @param array $result

	 */

	public function findSlide($condition='',$field=''){		

		try {

			$reslut = $this->m_slide->where($condition)->field($field)->find();			

			if(true == $reslut){

				return Common::errorArray(0, "查询成功",$reslut);

			}else{

				return Common::errorArray(1, "查询为空", $reslut);

			}

		}catch (Exception $ex){

			$this->errorLog(__CLASS__, __FUNCTION__, $ex);

			return  Common::errorArray(1, "数据库操作失败", $ex);

		}

	}

	

	/**

	 * 查询多个幻灯片数据

	 * @param $condition

	 * @param $limit

	 * @param $field

	 * @param $sort

	 * @param array $result

	 */

	public function findAllSlide($condition='',$limit='',$field='',$sort='add_time desc'){		

		try {

			$reslut = $this->m_slide->where($condition)->order($sort)->limit($limit)->field($field)->select();			

			if(true == $reslut){

				return Common::errorArray(0, "查询成功",$reslut);

			}else{

				return Common::errorArray(1, "查询为空", $reslut);

			}

		}catch (Exception $ex){

			$this->errorLog(__CLASS__, __FUNCTION__, $ex);

			return  Common::errorArray(1, "数据库操作失败", $ex);

		}

	}

	

	/**

	 * 更新幻灯片数据

	 * @param $condition

	 * @param $userInfo

	 * @param array $result

	 */

	public function updateSlide($condition,$userInfo){

		try {

			$reslut = $this->m_slide->where($condition)->update($userInfo);;		

			if($reslut >= 0){

				return Common::errorArray(0, "更新成功",$reslut);

			}else{

				return Common::errorArray(1, "更新失败", $reslut);

			}

		}catch (Exception $ex){

			$this->errorLog(__CLASS__, __FUNCTION__, $ex);

			return  Common::errorArray(1, "数据库操作失败", $ex);

		}

	}

	

	/**

	 * 删除幻灯片数据

	 * @param $condition

	 * @param array $result

	 */

	public function deleteSlide($condition){

		try {

			$reslut = $this->m_slide->where($condition)->delete();;		

			if(true == $reslut){

				return Common::errorArray(0, "删除成功",$reslut);

			}else{

				return Common::errorArray(1, "删除失败", $reslut);

			}

		}catch (Exception $ex){

			$this->errorLog(__CLASS__, __FUNCTION__, $ex);

			return  Common::errorArray(1, "数据库操作失败", $ex);

		}

	}

	

	/**

	 * 字段值加1

	 * @param $condition

	 * @param string $field

	 * @param int $optval

	 * @param array $reslut

	 */

	public function increaseField($condition,$field,$optval = 1){

		try {

			$reslut = $this->m_slide->where($condition)->setInc($field,$optval);;		

			if(true == $reslut){

				return Common::errorArray(0, "修改成功",$reslut);

			}else{

				return Common::errorArray(1, "修改失败", $reslut);

			}

		}catch (Exception $ex){

			$this->errorLog(__CLASS__, __FUNCTION__, $ex);

			return  Common::errorArray(1, "数据库操作失败", $ex);

		}

	}

	

	/**

	 * 字段值减1

	 * @param $condition

	 * @param string $field

	 * @param int $optval

	 * @param array $reslut

	 */

	public function decreaseField($condition,$field,$optval = 1){

		try {

			$reslut = $this->m_slide->where($condition)->setDec($field,$optval);;		

			if(true == $reslut){

				return Common::errorArray(0, "修改成功",$reslut);

			}else{

				return Common::errorArray(1, "修改失败", $reslut);

			}

		}catch (Exception $ex){

			$this->errorLog(__CLASS__, __FUNCTION__, $ex);

			return  Common::errorArray(1, "数据库操作失败", $ex);

		}

	}

	

	/**

	 * 分页获取数据幻灯片

	 */

	public function pagingSlide($page,$conditionList,$sort = '',$orList = null){

		$reslut = Common::paging('base_slide',$page,$conditionList,$sort,$orList);

		return  $reslut;  		

	}

	

}





?>